/*
 * @Description:
 * @Author: Zzt
 * @Date: 2022-11-10 16:49:18
 * @LastEditTime: 2023-01-18 10:49:37
 */
import { systemBakAndRecForTable, systemBakAndRecForStat } from '@/api/statistics/statistics';
import { createContext, useReducer, useEffect, useContext } from 'react';
import {
  SET_BAKCHART_DATA,
  SET_BAKTABLE_DATA,
  SET_RECCHART_DATA,
  SET_RECTABLE_DATA
} from '../constants';
import { BackupAndMaintenanceReducer } from '../reducers/BackupAndMaintenanceReducer';
const initialState = {
  dataBakList: {},
  dataRecList: {},
  chartBakList: [],
  chartRecList: []
};
const BackupAndMaintenanceContext = createContext();
const BackupAndMaintenanceContextProvider = (props) => {
  const [state, dispatch] = useReducer(BackupAndMaintenanceReducer, initialState);
  const actions = {
    setBakChartData(data) {
      systemBakAndRecForStat({ ...data, menuType: 1 }).then((res) => {
        const { data } = res;
        dispatch({ type: SET_BAKCHART_DATA, data });
      });
    },
    setRecChartData(data) {
      systemBakAndRecForStat({ ...data, menuType: 2 }).then((res) => {
        const { data } = res;
        dispatch({ type: SET_RECCHART_DATA, data });
      });
    },
    setBakTableData(data) {
      systemBakAndRecForTable({ ...data }).then((res) => {
        const { data } = res;
        console.log('datadata', data);
        dispatch({ type: SET_BAKTABLE_DATA, data });
      });
    },
    setRecTableData(data) {
      systemBakAndRecForTable({ ...data }).then((res) => {
        const { data } = res;
        console.log('datadata', data);
        dispatch({ type: SET_RECTABLE_DATA, data });
      });
    }
  };
  useEffect(() => {}, []);
  return (
    <BackupAndMaintenanceContext.Provider value={{ ...state, ...actions }}>
      {props.children}
    </BackupAndMaintenanceContext.Provider>
  );
};
export const useBackupAndMaintenanceContext = () => {
  return useContext(BackupAndMaintenanceContext);
};
export { BackupAndMaintenanceContext, BackupAndMaintenanceContextProvider };
